/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.viweb.storemanager.entity;

import com.viweb.storemanager.core.PropertyIndex;
import com.viweb.storemanager.core.SafeObject;
import java.text.Collator;
import java.text.RuleBasedCollator;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;

/**
 *
 * @author nhchung
 */
public class ShippingInvoice extends BaseEntity implements Comparable, Cloneable, SafeObject, PropertyIndex {

    //khai báo biến
    protected Object cloner;
    private Vendor vendor;
    private Date date;
    private Employee employee;
    private boolean isBillable;
    private ArrayList<ShippingDetail> shippingDetails = new ArrayList<ShippingDetail>();

    //khai báo hàm khởi tạo
    public ShippingInvoice() {
    }

    public ShippingInvoice(int id) {
        setId(id);
    }

    /**
     * @return the vendor
     */
    public Vendor getVendor() {
        return vendor;
    }

    /**
     * @param vendor the vendor to set
     */
    public void setVendor(Vendor vendor) {
        this.vendor = vendor;
    }

    /**
     * @return the date
     */
    public Date getDate() {
        return date;
    }

    /**
     * @param date the date to set
     */
    public void setDate(Date date) {
        this.date = date;
    }

    /**
     * @return the employee
     */
    public Employee getEmployee() {
        return employee;
    }

    /**
     * @param employee the employee to set
     */
    public void setEmployee(Employee employee) {
        this.employee = employee;
    }

    /**
     * @return the isBillable
     */
    public boolean isIsBillable() {
        return isBillable;
    }

    /**
     * @param isBillable the isBillable to set
     */
    public void setIsBillable(boolean isBillable) {
        this.isBillable = isBillable;
    }

    public ArrayList<ShippingDetail> getShippingDetails() {
        return shippingDetails;
    }

    public void setShippingDetails(ArrayList<ShippingDetail> shippingDetails) {
        this.shippingDetails = shippingDetails;
    }

    public Object getCloner() {
        return this.cloner;
    }

    public boolean validate() {

        return true;
    }

    //khai báo phương thức
    public Object getPropertyValue(int index) {
        String value = "";
        switch (index) {
            case 1:
                value = String.valueOf(getId());
                break;
            case 2:
                value = getVendor().getName();
                break;
            case 3:
                value = getDate().toString();
                break;
            case 4:
                value = getEmployee().getName();
                break;
            case 5:
                value = String.valueOf(isIsBillable());
                break;
            case 6:
                value = getDatemodifies().toString();
                break;
            case 7:
                value = String.valueOf(getStatus());
                break;
            case 8:
                value = getNote();
                break;
        }
        return value;
    }

    public void setPropertyValue(int index, Object value) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Class getPropertyClass(int index) {
        return String.class;
    }

    public int compareTo(Object object) {
        if (!(object instanceof WareHouse)) {
            throw new ClassCastException("Ngoại lệ: đối tượng thức uống không hợp lệ!");
        }

        RuleBasedCollator viCollator = (RuleBasedCollator) Collator.getInstance(new Locale("vi"));
        return viCollator.compare(this.getId(), ((ShippingInvoice) object).getId());
    }

    public void backup() {
        try {
            this.cloner = this.clone();
        } catch (CloneNotSupportedException ex) {
        }
    }

    public void restore() {
        this.setId(((ShippingInvoice) getCloner()).getId());
    }

    @Override
    public String toString() {
        return String.valueOf(this.getId());
    }
}
